package model.shader;

import java.awt.Color;
import java.util.Collection;

import raytracing.RayTracer;

import lib.common.Constants;
import model.lights.Light;
import model.primitive.IntersectionData;

public class GlassShader implements Shader {
	private String name;
	private double eta;
	private Color color;
	private double absorptionDistance;
	private Color absorptionColor;
	private double reflK;
	
	public GlassShader(String name, double eta, Color color) {
		this.name = name;
		this.color = new Color(color.getRGB());
		// default eta value = 1
		if (eta < 0) {
			this.eta = 1;
		} else {
			this.eta = eta;
		}
		
		this.absorptionColor = Constants.DEF_COLOR;
		this.absorptionDistance = 0;
	}
	
	public GlassShader(String name, double eta, Color color, double absDistance, Color absColor) {
		this(name, eta, color);
		
		this.absorptionColor = absColor;
		
		if (absDistance < 0) {
			this.absorptionDistance = 0; // disable by default
		} else {
			this.absorptionDistance = absDistance;
		}
		
		this.reflK = 0; // no reflection by default
		
	}
	
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}


	public Color getColor(Collection<Light> lights, IntersectionData state) {
		return this.color;
	}
	
	@Override
	public Color getColor(Collection<Light> lights, IntersectionData state,
			RayTracer rt) {
		return getColor(lights, state);
	}
	
	public double getAbsorptionDistance() {
		return absorptionDistance;
	}
	public void setAbsorptionDistance(double absorptionDistance) {
		this.absorptionDistance = absorptionDistance;
	}
	public Color getAbsorptionColor() {
		return absorptionColor;
	}
	public void setAbsorptionColor(Color absorptionColor) {
		this.absorptionColor = absorptionColor;
	}
	@Override
	public double getRefractionConstant() {
		return eta;
	}

	@Override
	public double getReflectionConstant() {
		return reflK;
	}
	
	public void setReflectionConstant(double reflK) {
		if (reflK > 0) {
			this.reflK = reflK;
		}
	}


}
